﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Minestorm.Evolved.IoC;
using Microsoft.Xna.Framework.Graphics;
using Minestorm.Evolved.Assets;
using Minestorm.Evolved.SceneObjects;
using Minestorm.Evolved.GameLogic;

namespace Minestorm.Evolved.Scenes
{
    public class MapScene : Scene
    {
        private MapCamera _camera;
        private MapLayout _mapLayout;

        public MapScene(IObjectFactory objectFactory, GraphicsDevice graphicsDevice)
            : base(objectFactory, graphicsDevice)
        {
            _mapLayout = new MapLayout();
        }

        public override void LoadContent()
        {
            AddObject(Camera = _camera = new MapCamera());

            _camera.MoveTo(_mapLayout.GetCurrentSelectedMineField().Position);

            AddObject(new MapBackground());
            AddObject(new Earth());

            foreach (var mineField in _mapLayout.MineFields)
                AddObject(mineField);

            AddObject(new Hud());

            base.LoadContent();
        }

        public override void HandleInput(InputState inputState)
        {
            var inputHelper = new MapInputStateHelper(inputState);

            if (inputHelper.PanRight())
                _camera.PanTo(_mapLayout.SelectNextMineField().Position);

            if (inputHelper.PanLeft())
                _camera.PanTo(_mapLayout.SelectPreviousMineField().Position);

            //if (inputHelper.PanUp())
            //    _camera.PanTo(new Vector3(_camera.PanningTo.X, _camera.PanningTo.Y + 5, _camera.PanningTo.Z));

            //if (inputHelper.PanDown())
            //    _camera.PanTo(new Vector3(_camera.PanningTo.X, _camera.PanningTo.Y - 5, _camera.PanningTo.Z));

            //if (inputHelper.ZoomIn())
            //    _camera.ZoomIn();

            //if (inputHelper.ZoomOut())
            //    _camera.ZoomOut();

            //if (inputHelper.PanToOrigin())
            //    _camera.PanTo(Vector3.Zero);

            base.HandleInput(inputState);
        }

        public override void Draw(GameTime gameTime)
        {
            SpriteBatch.Begin();

            base.Draw(gameTime);

            SpriteBatch.End();
        }
    }
}
